<template lang="html">
    <div>
        <div id="subtmpl">
		    <div class="div" @click="subtract">-</div>
		    <div class="div" v-text="count"></div>
		    <div class="div" @click="add">+</div>
	   </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            count: 1  //商品数据
        }
    },
    methods: {
        subtract(){
            this.count--;
            if (this.count < 1) {
                this.count = 1;
            }
            this.sendmessage();
        },
        add(){
            this.count++;
            this.sendmessage();
        },
        sendmessage(){
            this.$emit("dataobj", this.count) //子组件向父组件传值的方法。
        }
    }
}
</script>

<style lang="css" scoped>
#subtmpl .div{
		width: 40px;
		height: 25px;
		line-height: 25px;
		border: 1px solid #000;
		display: inline-block;
		text-align: center;
	}
</style>
